package com.hubiwei.gmall.realtime.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class AtguiguUtil {
    public static <T> List<T> toList(Iterable<T> it) {
        List<T> result = new ArrayList<>();
        for (T t : it) {
            result.add(t);
        }
        
        return result;
    }
    
    public static String toDateString(long ts, String... dateFormat) {
        String f = "yyyy-MM-dd";
        if (dateFormat.length == 1) {
            f = dateFormat[0];
        }
        
        return new SimpleDateFormat(f).format(ts);
    }
    
    public static long toTs(String dateTime, String... dateFormat) {
        String f = "yyyy-MM-dd HH:mm:ss";
        if (dateFormat.length == 1) {
            f = dateFormat[0];
        }
        try {
            return new SimpleDateFormat(f).parse(dateTime).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0L;
    }
    
}
